package com.lvcoding.sec3.secdemo3.validatecode.sms;

import cn.hutool.core.util.RandomUtil;
import com.lvcoding.sec3.secdemo3.config.SysConfig;
import com.lvcoding.sec3.secdemo3.validatecode.parent.ValidateCodeGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.ServletWebRequest;

/**
 * 短信验证码实现
 */
@Component
public class SmsCodeGenerator implements ValidateCodeGenerator {

    @Autowired
    private SysConfig sysConfig;

    @Override
    public SmsCode generate(ServletWebRequest request) {
        String smsCode = RandomUtil.randomString("0123456789",sysConfig.getSmsCode().getLength());
        return new SmsCode(smsCode, sysConfig.getSmsCode().getExpireIn());
    }
}
